package com.bjpowerndoe.ylb.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bjpowerndoe.ylb.domain.BidInfoPO;
import com.bjpowerndoe.ylb.domain.ProductInfoPO;
import com.bjpowerndoe.ylb.mapper.BidInfoMapper;
import com.bjpowerndoe.ylb.mapper.ProductInfoMapper;
import com.bjpowerndoe.ylb.mapper.UserMapper;
import com.bjpowerndoe.ylb.web.model.dto.AppInfoDTO;
import com.bjpowerndoe.ylb.web.service.inter.MangerService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RequiredArgsConstructor
@Service
public class MangerServiceImpl implements MangerService {


    private final ProductInfoMapper productInfoMapper;
    private final BidInfoMapper bidInfoMapper;
    private final UserMapper userMapper;
    @Override
    public AppInfoDTO getAppBaseInfo() {
        //注册用户数量
        Long registerUserCount = userMapper.selectCount(null);

        //累计投资金额
        QueryWrapper<BidInfoPO> condition = new QueryWrapper<>();
        condition.select("sum(bid_money) as bid_money");
        BigDecimal sumBidMoney = bidInfoMapper.selectOne(condition).getBidMoney();

        //利率平均值
        QueryWrapper<ProductInfoPO> wrapper = new QueryWrapper<>();
        wrapper.select("round(avg(rate),2) as rate");
        BigDecimal avgRate = productInfoMapper.selectOne(wrapper).getRate();

        return new AppInfoDTO(avgRate,sumBidMoney,registerUserCount);
    }
}
